/*
 * Cnanowire - computes current-voltage characteristic of bare cylindrical nanowire
 * Copyright (C) 2010  Oka Kurniawan
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
*/

#include "nfile.h"

using namespace itpp;

NFile::NFile()
{
	d_filename="output.dat";
	d_xLabel="X";
	d_yLabel="Y";
}

NFile::NFile(const std::string fname)
{
	d_filename=fname;
	d_xLabel="X";
	d_yLabel="Y";
}

NFile::~NFile()
{
}

void NFile::addData(std::string label, vec data, unsigned int col)
{
	switch(col)
	{
		case 0:
			d_xData=data;
			d_xLabel=label;
			break;
		case 1:
			d_yData=data;
			d_yLabel=label;
			break;
		default:
			d_xData=data;
			d_xLabel=label;
			break;
	}
}

void NFile::setFileName(std::string fname)
{
	d_filename=fname;
}

void NFile::saveToFile(std::string fname)
{
	setFileName(fname);
	saveToFile();
}

void NFile::saveToFile(void)
{
	std::ofstream myout(d_filename.c_str());
	if(!myout){
		std::cout<<"Cannot open file.\n";
	}
	myout << d_xLabel<<"\t "<<d_yLabel<<"\n";
	for (int i=0; i < d_xData.length(); i++)
	{
		myout << d_xData(i)<<"\t "<<d_yData(i)<<"\n";
	}
	myout.close();
}
